package com.jkhan.design.factory;

import java.lang.reflect.Proxy;

/**
 * @ClassName JDKProxy
 * @Description JDKProxy
 * @Author hjk
 * @Date 2023/1/9 22:45
 **/
public class JDKProxy {

    public static <T> T getProxy(Class<T> interfaceClass, ICacheAdapter iCacheAdapter) {
        JDKInvocationHandler handler = new JDKInvocationHandler(iCacheAdapter);
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Class<?>[] classes = interfaceClass.getInterfaces();
        return (T) Proxy.newProxyInstance(classLoader, new Class[]{classes[0]}, handler);
    }

}
